package com.vivien.example.springbootdemo.controller;

import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.vivien.example.springbootdemo.dto.ChatMultiModalRequest;
import com.vivien.example.springbootdemo.dto.ChatRequest;
import com.vivien.example.springbootdemo.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping(value = "/chat")
@CrossOrigin(origins = "http://localhost:8848")
public class ChatController {
    @Autowired
    public ChatService chatService;

    @RequestMapping(value = "/streamChat", method = RequestMethod.POST)
    public Flux<ServerSentEvent<String>> streamChat(@RequestBody ChatRequest chatRequest){
        Flux<ServerSentEvent<String>> result = chatService.streamChat(chatRequest.getName(), chatRequest.getUserInput());
        return result;
    }
//    @GetMapping(value = "/text")
//    public Result textChat(String name, String userInput){
//        String result = chatService.textChat(name, userInput);
//        // TODO 完成一些高级操作
//        return Result.success("", result);
//    }
    @PostMapping(value = "/streamMultiModal")
    public Flux<ServerSentEvent<String>> streamMultiModalChat(@RequestBody ChatMultiModalRequest chatMultiModalRequest) throws NoApiKeyException, UploadFileException {
        Flux<ServerSentEvent<String>> result = chatService.analyzeChat(chatMultiModalRequest);
        // TODO 完成一些高级操作
        return result;
    }

}
